package com.bluedon.ism.commons.entity;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * 角色表
 */
@Entity
@Table(name = "ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role implements java.io.Serializable {

	private Long rid;
	private String roleName;
	private String description;
	private Integer type;
	private Date createTime;
	private Account createUser;
	private Organization organization;
	private Date modifyTime;
	private Account modifyUser;
	/**
     * 1-系统内置，不可删除。 0-用户创建，可以删除
     */
	private Boolean isSystem;
	private Set<AccountRole> accountRoles = new HashSet<AccountRole>(0);
	private Set<RolePermission> rolePermissions = new HashSet<RolePermission>(0);


    @Id
    @GeneratedValue(strategy = IDENTITY)
	@Column(name = "RID", unique = true, nullable = false, precision = 10, scale = 0)
	public Long getRid() {
		return this.rid;
	}

	public void setRid(Long rid) {
		this.rid = rid;
	}

	@Column(name = "ROLE_NAME", nullable = false, unique = true)
	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Column(name = "DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column(name = "TYPE", precision = 1, scale = 0)
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	
	@Column(name = "CREATE_TIME")
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ORG_ID")
    public Organization getOrganization() {
        return this.organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }	    
	
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CREATE_USER")
	public Account getCreateUser() {
		return createUser;
	}

	public void setCreateUser(Account createUser) {
		this.createUser = createUser;
	}
	
    @Column(name = "IS_SYSTEM", precision = 1, scale = 0)
    public Boolean getIsSystem() {
        return isSystem;
    }

    public void setIsSystem(Boolean isSystem) {
        this.isSystem = isSystem;
    }
	
	@Column(name = "MODIFY_TIME")
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MODIFY_USER")
	public Account getModifyUser() {
		return modifyUser;
	}

	public void setModifyUser(Account modifyUser) {
		this.modifyUser = modifyUser;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "role")
	public Set<AccountRole> getAccountRoles() {
		return this.accountRoles;
	}
	public void setAccountRoles(Set<AccountRole> accountRoles) {
		this.accountRoles = accountRoles;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "role")
	public Set<RolePermission> getRolePermissions() {
		return this.rolePermissions;
	}

	public void setRolePermissions(Set<RolePermission> rolePermissions) {
		this.rolePermissions = rolePermissions;
	}
	
	

}
